import request from "../utils/request"
import {Dispatch} from "redux"
import {DataItem} from "../utils/index"

export let get_list = () => {
    return  async (dispatch:Dispatch) => {
        let {data,status} = await request.get("/api/list")
        status === 200 && dispatch({
            type:"GET_LIST",
            payload: data
        })
    }
}

export let get_charts = () => {
    return  async (dispatch:Dispatch) => {
        let {data,status} = await request.get("/api/charts")
        status === 200 && dispatch({
            type:"GET_CHAETS",
            payload: data
        })
    }
}

export let add_list = () => {
    return  async (dispatch:Dispatch) => {
        let {data,status} = await request.get("/api/list")
        status === 200 && dispatch({
            type:"ADD_LIST",
            payload: data[0].children
        })
    }
}
export let check_children_Data = (e:number)=>{
    return {
        type:"CHECK_CHILDREN_DATA",
        payload:e
    }
}


export let del_children_data = (item:DataItem)=>{
    return {
        type:"DELETE_SHOPCAR_DATA",
        payload:item
    }
}

export let set_details_data = (item:DataItem)=>{
    return {
        type:"set_details_data",
        payload:item
    }
}

export let like_data_count = (item:DataItem,show_Like:boolean)=>{
    return {
        type:"Like_DATA_COUNT",
        payload:{
            item,
            show_Like
        }
    }
}

export let search_value = (e:string)=>{
    return {
        type:"SEARCH_VALUE",
        payload:e
    }
}



export let filter_data = (e:string)=>{
    return {
        type:"FILTER_DATA",
        payload:e
    }
}

export let sort_data = (e:string)=>{
    return {
        type:"SORT_DATA",
        payload:e
    }
}



